/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 *
 * @author: jin Chen 
 * @date: Nov 14, 2003$
 * @version: 1.0
 */
package edu.psu.geovista.app.pcp;

import edu.psu.geovista.common.awt.event.dataloading.TSDataEvent;
import edu.psu.geovista.ui.event.*;

import javax.swing.*;
import java.awt.*;
import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.MethodDescriptor;
import java.beans.SimpleBeanInfo;
import java.lang.reflect.Method;
import java.net.URL;

public class PcpBeanInfo extends SimpleBeanInfo {
    public static final boolean DEBUG=false;
    final public static String RESOURCES="resources/";
    final public static String MODEL_ROOT= "edu/psu/geovista/app/pcp/";
    final public static String IMAGES=MODEL_ROOT+RESOURCES+"images/";

    private static Object[] methods
            ={"setData",new Class[]{Object[].class},
              "setDataModel",new Class[]{edu.psu.geovista.data.model.AppDataModel.class },

              "addColorArrayListener",new Class[]{ColorArrayListener.class},
              "addDataSetListener",new Class[]{DataSetListener.class},
              "addIndicationListener" ,new Class[]{IndicationListener.class },
              "addSelectionListener",new Class[]{SelectionListener.class },
               "colorArrayChanged",new Class[]{ColorArrayEvent.class },
               "dataSetChanged",new Class[]{DataSetEvent.class },
              "selectionChanged",new Class[]{SelectionEvent.class},
              "indicationChanged",new Class[]{IndicationEvent.class },
               "tsDataChanged",new Class[]{TSDataEvent.class }

            };

    //private static String[] methodNames={};

    private final static Class beanClass=DfPcp.class;
    public BeanDescriptor getBeanDescriptor() {
        return new BeanDescriptor(beanClass);
    }
    public MethodDescriptor[] getMethodDescriptors() {
          
           return this.generateMD() ;


        }

        private MethodDescriptor[] generateMD(){
             MethodDescriptor[] result=new MethodDescriptor[methods.length /2];
                 for (int i=0;i<methods.length ;i=i+2){
                     String methodName=(String) methods[i];
                     Class[] argument=(Class[]) methods[i+1];
                     try {
                         Method m=DfPcp.class.getMethod(methodName,argument);
                         result[i/2]=new MethodDescriptor(m);
                     } catch (NoSuchMethodException e) {

                         e.printStackTrace();  //To change body of catch statement use Options | File Templates.
                         continue;
                     } catch (SecurityException e) {
                         e.printStackTrace();  //To change body of catch statement use Options | File Templates.
                         continue;
                     }
                 }
            return result;
        }

        public Image getIcon(int iconKind){
            if (iconKind == BeanInfo.ICON_MONO_16x16 ||
                iconKind == BeanInfo.ICON_COLOR_16x16 )
            {

              java.awt.Image img = getImage(IMAGES+"Pcp16.gif");  //root is the folder contain this class
                if(DEBUG){
                    System.out.println("load pcp image:"+img);
                }
              return img;
            }
            if (iconKind == BeanInfo.ICON_MONO_32x32 ||
                iconKind == BeanInfo.ICON_COLOR_32x32 )
            {
              //if(Debug.isDebug()) {
                  String im = IMAGES + "Pcp32.gif";
                   if(DEBUG){
                    System.out.println("try load pcp image:"+im);
                }
              //}
              //java.awt.Image img = getImage(IMAGES +"PcpTs32.gif");
              java.awt.Image img = getImage(im);
              if(DEBUG){
                    System.out.println("loaded pcp image:"+img);
              }
              return img;
            }
            return null;

        }  //getIcon
        // loading images
        public static Image getImage(String fullName) {
            //String fullName=IMAGES+name;
            //todo change the name of class to current BeanInfo class
            ClassLoader cl=PcpBeanInfo.class.getClassLoader() ;
            URL url=cl.getResource(fullName);
            if (url == null) {
                System.out.println("image "+fullName+" not found");
                return null;
            }
            return new ImageIcon(url).getImage() ;
        }


}
